package com.wangijun.yuan.web.api;


import cn.dev33.satoken.annotation.SaCheckLogin;
import com.wangijun.yuan.web.base.CommonResult;
import com.wangijun.yuan.web.model.dto.UpdatePasswdParam;
import com.wangijun.yuan.web.model.dto.ChangeUserParam;
import com.wangijun.yuan.web.service.PersonService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "7-个人设置接口")
@RestController
@RequiredArgsConstructor
@RequestMapping("/setting")
public class SettingController {
    private final PersonService personService;



    @SaCheckLogin
    @Operation(summary = "用户信息更改")
    @PostMapping("/change-user")
    CommonResult<Boolean> updateLoginUser(@RequestBody ChangeUserParam param) {
        // 更新用户
        personService.updateLoginUser(param);
        return CommonResult.ok();
    }


    public record ChangeAvatarParam(
            @NotBlank
            @Schema(description = "用户头像地址")
            String avatar) {
    }

    @SaCheckLogin
    @Operation(summary = "用户头像更改", description = "用户头像更改")
    @PostMapping("/change-avatar")
    CommonResult<Boolean> changeAvatar(@RequestBody ChangeAvatarParam param) {
        personService.changeAvatar(param.avatar);
        return CommonResult.ok();
    }

    @SaCheckLogin
    @Operation(summary = "修改密码")
    @PostMapping("/change-passwd")
    CommonResult<Boolean> updatePasswd(@RequestBody UpdatePasswdParam param) {
        personService.updatePasswd(param);
        return CommonResult.ok();
    }


    @SaCheckLogin
    @Operation(summary = "设置密码")
    @PostMapping("/set-passwd")
    CommonResult<Boolean> setPasswd(@RequestBody UpdatePasswdParam param) {
        personService.setPasswd(param);
        return CommonResult.ok();
    }

    @SaCheckLogin
    @Operation(summary = "注销用户")
    @GetMapping("/cancel-user")
    CommonResult<Boolean> cancelUser() {
        personService.cancelUser();
        return CommonResult.ok();
    }
}
